<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>代扣文件列表</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        var grid = null;
        $(function () {
            $("#ligergrid1").ligerGrid({
                url: '<%=path%>/infside/infPostCollectMaster/initInfPostCollectMasterList.do',
                method : 'get',
                columns: [
                    { display: '状态', name: 'statusNm', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '代扣类型', name: 'typeNm', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '创建时间', name: 'crtTm', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    {
                        display: '发送文件',minWidth: 150,align: 'center',
                        render: function (rowdata, rowindex, value){
                            var h1='';
                            if(rowdata.sendFileName!=null){
                                if(rowdata.sendFilePath!=null){
                                    h1='<a href="<%=path%>/infside/infPostCollectMaster/downMasterFile.do?filename='+rowdata.sendFileName+'&filepath='+rowdata.sendFilePath+'">'+rowdata.sendFileName+'</a>';
                                }else{
                                    h1=rowdata.sendFileName;
                                }
                            }
                            return h1;
                        }
                    },
                    {
                        display: '回传文件',minWidth: 150,align: 'center',
                        render: function (rowdata, rowindex, value){
                            var h1='';
                            if(rowdata.returnFileName!=null){
                                if(rowdata.returnFilePath!=null){
                                    h1='<a href="<%=path%>/infside/infPostCollectMaster/downMasterFile.do?filename='+rowdata.returnFileName+'&filepath='+rowdata.returnFilePath+'">'+rowdata.returnFileName+'</a>';
                                }else{
                                    h1=rowdata.returnFileName;
                                }
                            }
                            return h1;
                        }
                    },
                    { display: '代扣开始日期', name: 'beginDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    { display: '代扣结束日期', name: 'endDate', minWidth: 100, render:renderDate, align: 'center', enabledSort:true},
                    //{ display: '放款批次号', name: 'payBatchCode', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '交易总笔数', name: 'totalQt', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '交易总金额', name: 'totalAtdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '解析成功笔数', name: 'parseQt', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '成功笔数', name: 'successQt', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '成功金额', name: 'successAtdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '失败笔数', name: 'failureQt', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '失败金额', name: 'failureAtdou', minWidth: 100, align: 'center', enabledSort:true},
                    { display: '银行批次号', name: 'batchCode', minWidth: 100, align: 'center', enabledSort:true},
                    {
                        display: '操作',minWidth: 100,align: 'center',
                        render: function (rowdata, rowindex, value){
                            var h1='<a href="javascript:void(0);" onclick="searchProjectDetail(\''+rowdata.id+'\')">明细</a>';
                            var h2='<span style="color:#C9C9C9;">删除</span>';
                            if(rowdata.status=='sendWait' || StringUtils.isEmpty(rowdata.status)){
                                h2='<a href="javascript:void(0);" onclick="deleteMasterById(\''+rowdata.id+'\')">删除</a>';

                            }
                            return h1+'&nbsp;&nbsp;&nbsp;&nbsp;'+h2;
                        }
                    }
                ],
                pageSize:10,
                root:'rows',
                record:'total',
                hideLoadButton : true,
                width: '100%',
                height:380,
                heightDiff:-2,
                checkbox:true,
                rownumbers:true
            });
            grid = liger.get("ligergrid1");
            $("#searchBar").ligerForm();
            $("#searchBtn").click(function(event) {
                var form = new liger.get("searchBar");
                var data = form.getData();
                console.log(data);
                for (name in data){
                    grid.setParm(name,data[name]);
                };
                grid.reload();
            });
            $("#clearBtn").click(function(event) {
                clearLigerForm("searchBar");
            });
        });
        //明细
        function searchProjectDetail(_masterId){
            if (parent.pageInTab) {
                parent.pageInApp.masterId=_masterId;
                parent.pageInTab.selectTabItem('infPostCollectDetail');
                parent.pageInTab.reload('infPostCollectDetail');
            }
        }
        //格式化时间
        function renderDate(rowdata, index, value){
            var dateStr = "";
            if(null != value){
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
            }
            return dateStr;
        }
        //发送数据
        function sendDeductions(){
            var selectedRows = grid.getSelectedRows();
            if(selectedRows.length == 0){
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
                return;
            }

            var _ids = [];
            for ( var index in selectedRows) {
            	var _status = selectedRows[index].status;
                if(_status=='sendWait' || StringUtils.isEmpty(_status)){
                    _ids.push(selectedRows[index].id);
                }else{
                    $.ligerDialog.SQalert({content: "请选择待发送状态的数据" , SQ_type: "warning" });
                    return;
                }
            }
            $.ligerDialog.confirm("是否确认发送?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:{ids:JSON.stringify(_ids)},
                    url: '<%=path%>/infside/infPostCollectMaster/sendDeductions.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        //回传数据
        function receiveDeductions(){
            var selectedRows = grid.getSelectedRows();
            if(selectedRows.length == 0){
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
                return;
            }

            var _ids = [];
            for ( var index in selectedRows) {
                if(selectedRows[index].status=='receiveWait' || selectedRows[index].status=='parseFailure'){
                    _ids.push(selectedRows[index].id);
                }else{
                    $.ligerDialog.SQalert({content: "请选择待回传状态的数据" , SQ_type: "warning" });
                    return;
                }
            }
            $.ligerDialog.confirm("是否确认获取回传?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:{ids:JSON.stringify(_ids)},
                    url: '<%=path%>/infside/infPostCollectMaster/receiveDeductions.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        //删除数据
        function deleteMasterById(_masterId){
            $.ligerDialog.confirm("是否确认删除?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:{masterId:_masterId},
                    url: '<%=path%>/infside/infPostCollectMaster/deleteMasterById.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            grid.reload();
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
    </script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox col_33">
                    <div class="label">生成日期</div>
                    <div class="field">
                        <input name="crtTm" id="crtTm" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">状态</div>
                    <div class="field">
                        <select name="status"  id="status"  disabled="disabled">
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${statuslist}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <%--
                <div class="fieldBox col_33">
                    <div class="label">代扣时间(起)</div>
                    <div class="field">
                        <input name="beginDate" id="1" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">代扣时间(止)</div>
                    <div class="field">
                        <input name="endDate" id="2" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                --%>
                <div class="fieldBox">
                    <div class="label">代扣类型</div>
                    <div class="field">
                        <select name="type"  id="type"  disabled="disabled">
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${typelist}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <span id="sendDeductions" class="sq-button sq-button-hasicon" onclick="sendDeductions()"><i class="sqBtnIco_9"></i>发送</span>
                    <span id="receiveDeductions" class="sq-button sq-button-hasicon" onclick="receiveDeductions()"><i class="sqBtnIco_8"></i>获取回传</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
<span>
    代扣文件生成规则：
			<br>
            1.按照时间段选择代扣日期（支付表应付日期，罚息取当天）
			<br>
			2.上午11点下午4点为邮储处理文件时间，如果要发送2次文件，需要第一次在11点前，第二次在4点前
			<br>
			3.验证代扣生成文件总数不能超过10，超过下午4点当天不能再生成文件
            <br>
			4.代扣文件根据批次号生成，文件个数跟批次号一致，明细选取代扣卡允许代扣的用户
			<br>
			代扣文件操作按钮：明细：查看文件代扣记录；发送：发送文件；删除：删除文件重新生成；获取回传：从邮储获取文件；
</span>
</body>
</html>
